import 'dart:developer';
import 'dart:io' show Platform;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'
    show BMFMapSDK, BMF_COORD_TYPE;
import 'package:flutter_bmfmap_example/models/deviceinfomodel.dart';
import 'package:flutter_bmfmap_example/models/familyinfomodel.dart';
import 'package:flutter_bmfmap_example/models/orderinfomodel.dart';
import 'package:flutter_bmfmap_example/pages/loginpage/Login_page.dart';
import 'package:flutter_bmfmap_example/tool/HYSizeFit%20.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:provider/provider.dart';

import 'models/collectioninfomodel.dart';
import 'models/marketinfomodel.dart';
import 'models/userinformodel.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  if (Platform.isAndroid) {
    // 以下两行 设置android状态栏为透明的沉浸。写在组件渲染之后，是为了在渲染后进行set赋值，覆盖状态栏，写在渲染之前MaterialApp组件会覆盖掉这个值。
    SystemUiOverlayStyle systemUiOverlayStyle =
        SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }

  // 百度地图sdk初始化鉴权
  if (Platform.isIOS) {
    BMFMapSDK.setApiKeyAndCoordType(
        '请在此输入您在开放平台上申请的API_KEY', BMF_COORD_TYPE.BD09LL);
  } else if (Platform.isAndroid) {
    // Android 目前不支持接口设置Apikey,
    // 请在主工程的Manifest文件里设置，详细配置方法请参考官网(https://lbsyun.baidu.com/)demo
    BMFMapSDK.setCoordType(BMF_COORD_TYPE.BD09LL);
  }

  // runApp(new MyApp());
  // runApp(
  //   ChangeNotifierProvider<Userinfomodel>(
  //     create: (_) {
  //       return Userinfomodel();
  //     },
  //     child: MyApp(),
  //   ),
  // );

  runApp(
    /// Providers are above [MyApp] instead of inside it, so that tests
    /// can use [MyApp] while mocking the providers
    MultiProvider(
      providers: [
        ChangeNotifierProvider<Collectioninfomodel>(
          //这个提供的对象必须支持ChangeNotifier
          create: (_) => Collectioninfomodel(),
        ),
        ChangeNotifierProvider<Userinfomodel>(
          //这个提供的对象必须支持ChangeNotifier
          create: (_) => Userinfomodel(),
        ),
        ChangeNotifierProvider<Shoppingcatmodel>(
          //这个提供的对象必须支持ChangeNotifier
          create: (_) => Shoppingcatmodel(),
        ),
        ChangeNotifierProvider<DeviceInfomodel>(
          //这个提供的对象必须支持ChangeNotifier
          create: (_) => DeviceInfomodel(),
        ),
        ChangeNotifierProvider<Orderinfomodel>(
          //这个提供的对象必须支持ChangeNotifier
          create: (_) => Orderinfomodel(),
        ),
        ChangeNotifierProvider<FamilyInfomodel>(
          //这个提供的对象必须支持ChangeNotifier
          create: (_) => FamilyInfomodel(),
        ),
      ],
      child: MyApp(),
    ),
  );
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      builder: (BuildContext contonxt, Widget child) {
        return Material(
          child: FlutterEasyLoading(child: child),
        );
      },
      debugShowCheckedModeBanner: false,
      home: RootPage(),
    );
  }
}

class RootPage extends StatelessWidget {
  const RootPage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    HYSizeFit.initialize(context);
    return Scaffold(
      body: LoginPage(),
    );
  }
}
